home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / icu-1.3.1 / icu-bin / include / utypes.h < prev   
C/C++ Source or Header  |  2000-02-23  |  13KB  |  347 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright Taligent, Inc.,  1996, 1997                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1996-1999     *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  10. *                                                                             *
  11. *******************************************************************************
  12. *
  13. *  FILE NAME : UTYPES.H (formerly ptypes.h)
  14. *
  15. *   Date        Name        Description
  16. *   12/11/96    helena      Creation.
  17. *   02/27/97    aliu        Added typedefs for UClassID, int8, int16, int32,
  18. *                           uint8, uint16, and uint32.
  19. *   04/01/97    aliu        Added XP_CPLUSPLUS and modified to work under C as
  20. *                            well as C++.
  21. *                           Modified to use memcpy() for icu_arrayCopy() fns.
  22. *   04/14/97    aliu        Added TPlatformUtilities.
  23. *   05/07/97    aliu        Added import/export specifiers (replacing the old
  24. *                           broken EXT_CLASS).  Added version number for our
  25. *                           code.  Cleaned up header.
  26. *    6/20/97    helena      Java class name change.
  27. *   08/11/98    stephen     UErrorCode changed from typedef to enum
  28. *   08/12/98    erm         Changed T_ANALYTIC_PACKAGE_VERSION to 3
  29. *   08/14/98    stephen     Added icu_arrayCopy() for int8_t, int16_t, int32_t
  30. *   12/09/98    jfitz       Added BUFFER_OVERFLOW_ERROR (bug 1100066)
  31. *   04/20/99    stephen     Cleaned up & reworked for autoconf.
  32. *                           Renamed to utypes.h.
  33. *   05/05/99    stephen     Changed to use <inttypes.h>
  34. *******************************************************************************
  35. */
  36.  
  37. #ifndef UTYPES_H
  38. #define UTYPES_H
  39.  
  40. #include <memory.h>
  41. #include <wchar.h>
  42. #include <stdlib.h>
  43.  
  44. /*===========================================================================*/
  45. /* Include platform-dependent definitions                                    */
  46. /* which are contained in the platform-specific file platform.h              */
  47. /*===========================================================================*/
  48.  
  49. #if defined(WIN32) || defined(_WIN32)
  50. #   include "pwin32.h"
  51. #elif defined(__OS2__)
  52. #   include "pos2.h"
  53. #elif defined(__OS400__)
  54. #   include "pos400.h"
  55. #else
  56. #   include "platform.h"
  57. #endif
  58.  
  59. /* XP_CPLUSPLUS is a cross-platform symbol which should be defined when 
  60.    using C++.  It should not be defined when compiling under C. */
  61. #ifdef __cplusplus
  62. #   ifndef XP_CPLUSPLUS
  63. #       define XP_CPLUSPLUS
  64. #   endif
  65. #else
  66. #   undef XP_CPLUSPLUS
  67. #endif
  68.  
  69. /*===========================================================================*/
  70. /* Boolean data type                                                         */
  71. /*===========================================================================*/
  72.  
  73. #if ! HAVE_BOOL_T
  74. typedef int8_t bool_t;
  75. #endif
  76.  
  77. #ifndef TRUE
  78. #   define TRUE  1
  79. #endif
  80. #ifndef FALSE
  81. #   define FALSE 0
  82. #endif
  83.  
  84. /*===========================================================================*/
  85. /* Unicode string offset                                                     */
  86. /*===========================================================================*/
  87. typedef int32_t UTextOffset;
  88.  
  89. /*===========================================================================*/
  90. /* Unicode character                                                         */
  91. /*===========================================================================*/
  92. typedef uint16_t UChar;
  93.  
  94. /*===========================================================================*/
  95. /* ICU version number                                                        */
  96. /*===========================================================================*/
  97.  
  98. /**
  99.  * ICU package code version number.
  100.  * This version number is incremented if and only if the code has changed
  101.  * in a binary incompatible way.  For example, if the algorithm for generating
  102.  * sort keys has changed, this code version must be incremented.
  103.  *
  104.  * This is for internal use only.  Clients should use
  105.  * ResourceBundle::getVersionNumber().
  106.  *
  107.  * ResourceBundle::getVersionNumber() returns a full version number
  108.  * for a resource, which consists of this code version number concatenated
  109.  * with the ResourceBundle data file version number.
  110.  */
  111. #define ICU_VERSION "3"
  112.  
  113.  
  114. /*===========================================================================*/
  115. /* For C wrappers, we use the symbol U_CAPI.                                   */
  116. /* This works properly if the includer is C or C++.                          */
  117. /* Functions are declared   U_CAPI return-type U_EXPORT2 function-name() ...   */
  118. /*===========================================================================*/
  119.  
  120. #ifdef XP_CPLUSPLUS
  121. #   define U_CFUNC extern "C"
  122. #   define U_CDECL_BEGIN extern "C" {
  123. #   define U_CDECL_END   }
  124. #else
  125. #   define U_CFUNC
  126. #   define U_CDECL_BEGIN
  127. #   define U_CDECL_END
  128. #endif
  129. #define U_CAPI U_CFUNC U_EXPORT
  130.  
  131.  
  132. /* Define NULL pointer value  if it isn't already defined */
  133.  
  134. #ifndef NULL
  135. #ifdef XP_CPLUSPLUS
  136. #define NULL    0
  137. #else
  138. #define NULL    ((void *)0)
  139. #endif
  140. #endif
  141.  
  142. /* Maximum value of a (void*) - use to indicate the limit of
  143.    an 'infinite' buffer.  */
  144. #define U_MAX_PTR ((void*)-1)
  145.  
  146. /*===========================================================================*/
  147. /* Calendar/TimeZone data types                                              */
  148. /*===========================================================================*/
  149.  
  150. /**
  151.  * Date and Time data type.
  152.  * This is a primitive data type that holds the date and time
  153.  * as the number of milliseconds since 1970-jan-01, 00:00 UTC.
  154.  * UTC leap seconds are ignored.
  155.  */
  156. typedef double UDate;
  157.  
  158. /* Common time manipulation constants */
  159. #define U_MILLIS_PER_SECOND        (1000)
  160. #define U_MILLIS_PER_MINUTE       (60000)
  161. #define U_MILLIS_PER_HOUR       (3600000)
  162. #define U_MILLIS_PER_DAY       (86400000)
  163.  
  164.  
  165. /*===========================================================================*/
  166. /* UClassID-based RTTI */
  167. /*===========================================================================*/
  168.  
  169. /**
  170.  * UClassID is used to identify classes without using RTTI, since RTTI
  171.  * is not yet supported by all C++ compilers.  Each class hierarchy which needs
  172.  * to implement polymorphic clone() or operator==() defines two methods,
  173.  * described in detail below.  UClassID values can be compared using
  174.  * operator==(). Nothing else should be done with them.
  175.  *
  176.  * getDynamicClassID() is declared in the base class of the hierarchy as
  177.  * a pure virtual.  Each concrete subclass implements it in the same way:
  178.  *
  179.  *      class Base {
  180.  *      public:
  181.  *          virtual UClassID getDynamicClassID() const = 0;
  182.  *      }
  183.  *
  184.  *      class Derived {
  185.  *      public:
  186.  *          virtual UClassID getDynamicClassID() const
  187.  *            { return Derived::getStaticClassID(); }
  188.  *      }
  189.  *
  190.  * Each concrete class implements getStaticClassID() as well, which allows
  191.  * clients to test for a specific type.
  192.  *
  193.  *      class Derived {
  194.  *      public:
  195.  *          static UClassID getStaticClassID();
  196.  *      private:
  197.  *          static char fgClassID;
  198.  *      }
  199.  *
  200.  *      // In Derived.cpp:
  201.  *      UClassID Derived::getStaticClassID()
  202.  *        { return (UClassID)&Derived::fgClassID; }
  203.  *      char Derived::fgClassID = 0; // Value is irrelevant
  204.  */
  205.  
  206. typedef void* UClassID;
  207.  
  208. /*===========================================================================*/
  209. /* Shared library/DLL import-export API control                              */
  210. /*===========================================================================*/
  211.  
  212. /**
  213.  * Control of symbol import/export.
  214.  * The ICU is separated into two libraries.
  215.  */
  216.  
  217.  
  218. #ifdef U_COMMON_IMPLEMENTATION
  219. #define U_COMMON_API  U_EXPORT
  220. #define U_I18N_API    U_IMPORT
  221. #elif defined(U_I18N_IMPLEMENTATION)
  222. #define U_COMMON_API  U_IMPORT
  223. #define U_I18N_API    U_EXPORT
  224. #else
  225. #define U_COMMON_API  U_IMPORT
  226. #define U_I18N_API    U_IMPORT
  227. #endif
  228. /*===========================================================================*/
  229. /* UErrorCode */
  230. /*===========================================================================*/
  231.  
  232. /** Error code to replace exception handling */
  233. enum UErrorCode {
  234.     U_ERROR_INFO_START        = -128,     /* Start of information results (semantically successful) */
  235.     U_USING_FALLBACK_ERROR    = -128,
  236.     U_USING_DEFAULT_ERROR     = -127,
  237.     U_ERROR_INFO_LIMIT,
  238.  
  239.     U_ZERO_ERROR              =  0,       /* success */
  240.  
  241.     U_ILLEGAL_ARGUMENT_ERROR  =  1,       /* Start of codes indicating failure */
  242.     U_MISSING_RESOURCE_ERROR  =  2,
  243.     U_INVALID_FORMAT_ERROR    =  3,
  244.     U_FILE_ACCESS_ERROR       =  4,
  245.     U_INTERNAL_PROGRAM_ERROR  =  5,       /* Indicates a bug in the library code */
  246.     U_MESSAGE_PARSE_ERROR     =  6,
  247.     U_MEMORY_ALLOCATION_ERROR =  7,       /* Memory allocation error */
  248.     U_INDEX_OUTOFBOUNDS_ERROR =  8,
  249.     U_PARSE_ERROR             =  9,       /* Equivalent to Java ParseException */
  250.     U_INVALID_CHAR_FOUND      = 10,       /* In the Character conversion routines: Invalid character or sequence was encountered*/
  251.     U_TRUNCATED_CHAR_FOUND    = 11,       /* In the Character conversion routines: More bytes are required to complete the conversion successfully*/
  252.     U_ILLEGAL_CHAR_FOUND      = 12,       /* In codeset conversion: a sequence that does NOT belong in the codepage has been encountered*/
  253.     U_INVALID_TABLE_FORMAT    = 13,       /* Conversion table file found, but corrupted*/
  254.     U_INVALID_TABLE_FILE      = 14,       /* Conversion table file not found*/
  255.     U_BUFFER_OVERFLOW_ERROR   = 15,       /* A result would not fit in the supplied buffer */
  256.     U_UNSUPPORTED_ERROR       = 16,       /* Requested operation not supported in current context */
  257.     U_ERROR_LIMIT
  258. };
  259.  
  260. #ifndef XP_CPLUSPLUS
  261. typedef enum UErrorCode UErrorCode;
  262. #endif
  263.  
  264. /* Use the following to determine if an UErrorCode represents */
  265. /* operational success or failure. */
  266. #ifdef XP_CPLUSPLUS
  267. inline bool_t U_SUCCESS(UErrorCode code) { return (bool_t)(code<=U_ZERO_ERROR); }
  268. inline bool_t U_FAILURE(UErrorCode code) { return (bool_t)(code>U_ZERO_ERROR); }
  269. #else
  270. #define U_SUCCESS(x) ((x)<=U_ZERO_ERROR)
  271. #define U_FAILURE(x) ((x)>U_ZERO_ERROR)
  272. #endif
  273.  
  274.  
  275. /* Casting function for int32_t (backward compatibility version, here until
  276.    T_INT32 is replaced) */
  277. #define T_INT32(i) ((int32_t)i)
  278.  
  279.  
  280. /*===========================================================================*/
  281. /* Debugging */
  282. /*===========================================================================*/
  283.  
  284. /* remove this */
  285.  
  286. /* This function is useful for debugging; it returns the text name */
  287. /* of an UErrorCode result.  This is not the most efficient way of */
  288. /* doing this but it's just for Debug builds anyway. */
  289.  
  290. /* Do not use these arrays directly: they will move to a .c file! */
  291. static const char *
  292. _uErrorInfoName[U_ERROR_INFO_LIMIT-U_ERROR_INFO_START]={
  293.     "U_USING_FALLBACK_ERROR",
  294.     "U_USING_DEFAULT_ERROR"
  295. };
  296.  
  297. static const char *
  298. _uErrorName[U_ERROR_LIMIT]={
  299.     "U_ZERO_ERROR",
  300.  
  301.     "U_ILLEGAL_ARGUMENT_ERROR",
  302.     "U_MISSING_RESOURCE_ERROR",
  303.     "U_INVALID_FORMAT_ERROR",
  304.     "U_FILE_ACCESS_ERROR",
  305.     "U_INTERNAL_PROGRAM_ERROR",
  306.     "U_MESSAGE_PARSE_ERROR",
  307.     "U_MEMORY_ALLOCATION_ERROR",
  308.     "U_INDEX_OUTOFBOUNDS_ERROR",
  309.     "U_PARSE_ERROR",
  310.     "U_INVALID_CHAR_FOUND",
  311.     "U_TRUNCATED_CHAR_FOUND",
  312.     "U_ILLEGAL_CHAR_FOUND",
  313.     "U_INVALID_TABLE_FORMAT",
  314.     "U_INVALID_TABLE_FILE",
  315.     "U_BUFFER_OVERFLOW_ERROR",
  316.     "U_UNSUPPORTED_ERROR"
  317. };
  318.  
  319. #ifdef XP_CPLUSPLUS
  320. inline const char *
  321. errorName(UErrorCode code)
  322. {
  323.     if(code>=0 && code<U_ERROR_LIMIT) {
  324.         return _uErrorName[code];
  325.     } else if(code>=U_ERROR_INFO_START && code<U_ERROR_INFO_LIMIT) {
  326.         return _uErrorInfoName[code-U_ERROR_INFO_START];
  327.     } else {
  328.         return "[BOGUS UErrorCode]";
  329.     }
  330. }
  331. #else
  332. #   define errorName(code) \
  333.         ((code)>=0 && (code)<U_ERROR_LIMIT) ? \
  334.             _uErrorName[code] : \
  335.             ((code)>=U_ERROR_INFO_START && (code)<U_ERROR_INFO_LIMIT) ? \
  336.                 _uErrorInfoName[code-U_ERROR_INFO_START] : \
  337.                 "[BOGUS UErrorCode]"
  338. #endif
  339.  
  340. /*===========================================================================*/
  341. /* Include header for platform utilies */
  342. /*===========================================================================*/
  343.  
  344. #include "putil.h"
  345.  
  346. #endif /* _UTYPES */
  347.